﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SES.CMS.BL;
using SES.CMS.DO;
using System.Data;
using System.Web.UI.HtmlControls;
using System.Net.Mail;
using System.Web.Security;
using System.Text.RegularExpressions;
using SES.CMS.AdminCP;

namespace SES.CMS
{
    public partial class Registration : System.Web.UI.Page
    {
        cmsCustomerDO objCust = new cmsCustomerDO();
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Initobject()
        {

            objCust = new cmsCustomerBL().Select(objCust);
            objCust.FullName = txtName.Text;

            objCust.Address = txtAdress.Text;

            objCust.Password = Ultility.EncryptMd5(txtPassword.Text.Trim());
            objCust.Phone = txtPhone.Text;

            if (rdoNam.Checked)
            {
                objCust.Sex = true;
            }
            else
            {
                objCust.Sex = false;
            }
            if (txtBirtday.Text != "")
            {
                objCust.Brithday = Convert.ToDateTime(txtBirtday.Text);
            }
            else
                objCust.Brithday = DateTime.Now;
            objCust.RegisterDay = DateTime.Now;
            objCust.IsEnable = true;
            objCust.IsVangLai = false;
        }
        protected void btnDangky_Click(object sender, EventArgs e)
        {


            Initobject();

            DataTable dtUser = new cmsCustomerBL().SelectRegistration(txtUserName.Text);
            DataTable dtEmail = new cmsCustomerBL().SelectEmail(txtEmail.Text);
            if (dtUser.Rows.Count > 0)
            {

                Functions.Alert("Tên đăng nhập đã tồn tại");
                txtUserName.Focus();
            }
            else if (dtEmail.Rows.Count > 0)
            {
                Functions.Alert("Email đã tồn tại");
                txtEmail.Focus();
            }
            else
            {
                objCust.UserName = txtUserName.Text.Trim();
                objCust.Email = txtEmail.Text;
                new cmsCustomerBL().Insert(objCust);
                Functions.Alert("Đăng ký thành công!!!", "/Login.aspx");
            }

        }

        protected void btnLamlai_Click(object sender, EventArgs e)
        {
            txtAdress.Text = "";
            txtBirtday.Text = "";
            txtEmail.Text = "";
            txtName.Text = "";
            txtPass.Text = "";
            txtPassword.Text = "";
            txtPhone.Text = "";
            txtUserName.Text = "";
            txtUserName.Focus();
        }

        protected void btnhuy_Click(object sender, EventArgs e)
        {
            Response.Redirect("/Login.aspx");
        }
    }
}